package com.cos.lession47.dao.impl;

import com.cos.lession47.dao.EmpDao;
import com.cos.lession47.entity.Emp;
import com.cos.lession47.util.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @author: COS
 * @time: 2022/2/28 14:33
 * @description:
 */
public class EmpDaoImpl implements EmpDao {
    private QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());

    @Override
    public int changePwd(String pwd, Integer eno) throws SQLException {
        return qr.update("update emp set pwd = ? where eno = ?",pwd,eno);
    }

    @Override
    public Emp getEmpInfoByPhone(String phone) throws SQLException {
        return qr.query("select * from emp where phone=?",new BeanHandler<>(Emp.class),phone);
    }

    @Override
    public int addEmp(Emp e) throws SQLException {
        return qr.update("insert into emp values (default,?,?,?,?,?,?,?)",
                e.getEname(),e.getEsex(),e.getSalary(),e.getPwd(),e.getBornDate(),e.getDno(),e.getPhone());
    }
}
